package com.jqq.homework;

import java.util.Arrays;

/**
 * @author 姬倩倩
 * @version 1.0
 */
public class Homework01 {
    public static void main(String[] args) {
        String str = "abcdef";
        System.out.println("==原str===");
        System.out.println(str);
        String reStr = null;
        try {
            reStr = reverse(str, 1, 4);
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return;
        }
        System.out.println("==翻转1-4位后的str===");
        System.out.println(reStr);
    }

    public static String reverse(String str, int start, int end) {

        if(!(str!=null && start>=0 &&end >start &&end<str.length()-1)){
            throw new RuntimeException("参数不正确");
        }
        char[] chars = str.toCharArray();
        for (int i = start, j = end; i < j; i++, j--) {
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
        }
        return new String(chars);
    }
}
